package com.byxm.wlgw.query;

import com.byxm.wlgw.bean.DdxxBean;
import com.byxm.wlgw.bean.DdxxpxBean;
import com.byxm.wlgw.bean.SpxxBean;
import com.byxm.wlgw.bean.SpxxpxBean;
import com.byxm.wlgw.common.ComUtil;
import com.byxm.wlgw.common.Pages;

public class DdxxQuery {
	/**
	 * 查找所有订单信息 带分页
	 */
	public String findDdxxAll(DdxxBean ddxx,Pages page){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from");
		sql.append(" (");
		sql.append("select top ").append(page.getPageNum());
		sql.append("* from");
		sql.append(" (");
		sql.append("select top(").append(page.getPageNumFin()).append("*").append(page.getCpage()).append(")");
		sql.append(" t1.* from ddxx t1 where 1=1");
		if(ddxx.getJyzt()!=0){
			sql.append(" and jyzt=").append(ddxx.getJyzt());
		}
		if(!ComUtil.isNull(ddxx.getBeginTime())&&!ComUtil.isNull(ddxx.getEndTime())){
			sql.append(" and ddjlsj>='").append(ddxx.getBeginTime()).append("'");
			sql.append(" and ddjlsj<='").append(ddxx.getEndTime()).append("'");
		}
		if(!ComUtil.isNull(ddxx.getSearchString().trim())){
			sql.append(" and (ddxxid like'%").append(ddxx.getSearchString()).append("%'");
			sql.append(" or sjhm='").append(ddxx.getSearchString()).append("'");
			sql.append(" or shrxm='").append(ddxx.getSearchString()).append("'");
			sql.append(")");
		}
	
		DdxxpxBean ddxxpxBean=ddxx.getDdxxpxBean();//获得排序对象
		sql.append(" order by ").append(ddxxpxBean.getPxzd()).append(" asc");
		sql.append(")as spxxtba order by ").append(ddxxpxBean.getPxzd()).append(" desc");
		sql.append(")as spxxtbb order by ").append(ddxxpxBean.getPxzd()).append(" ").append(ddxxpxBean.getSqlgjz());
			
		return sql.toString();
	}
	/**
	 * 插入订单信息
	 * @return
	 */
    public String getInsertDdxxQuery(){
    	StringBuffer sql = new StringBuffer();
    	sql.append("insert into ddxx (ddxxid,yhxxid,shxxid,ddjlsj,fhfs,fkzt,fhzt,jyzt,jyze,shdz,sjhm,yb,shrxm)values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
    	return sql.toString();
    }
    public String findDdxxSql(){
    	StringBuffer sql=new StringBuffer();
    	sql.append("select * from ddxx where ddxxid=?");
    	return sql.toString();
    }
    /**
     * 获取ddxx总条数
     * @param spxx
     * @return
     */
	public String getDdxxCnt(DdxxBean ddxx){
		StringBuffer sql = new StringBuffer();
		sql.append("select count(*)as ct from ddxx where 1=1");
		if(ddxx.getJyzt()!=0){
			sql.append(" and jyzt=").append(ddxx.getJyzt());	//交易状态
		}
		if(!ComUtil.isNull(ddxx.getSearchString().trim())){
			sql.append(" and (ddxxid like'%").append(ddxx.getSearchString()).append("%'");
			sql.append(" or sjhm='").append(ddxx.getSearchString()).append("'");
			sql.append(" or shrxm='").append(ddxx.getSearchString()).append("'");
			sql.append(")");
		}
		
		return sql.toString();
	}
	/**
	 * 更新交易状态 
	 * @return
	 */
	public String updateDdxxJyzt(){
		StringBuffer sql=new StringBuffer();
		sql.append("update ddxx set jyzt=? where ddxxid=?");
		return sql.toString();
	}
	
	/**
	 * 查询订单信息
	 * @return
	 */
	public String findDdxx(){
		StringBuffer sql=new StringBuffer();
		sql.append("select ddxxid,ddjlsj from ddxx where yhxxid=? order by ddjlsj desc");
		return sql.toString();
	}
	

}
